﻿#pragma once
#include <memory>
#include <QObject>

#define REGISTER_GETTER_H(addr)\
	Q_D(const FavoriteAttributes);\
	return d->m_vm.at(addr) >> 8;

#define REGISTER_GETTER_L(addr)\
	Q_D(const FavoriteAttributes);\
	return d->m_vm.at(addr) & 0x00ff;

#define REGISTER_GETTER(addr) \
	Q_D(const FavoriteAttributes);\
	return d->m_vm.at(addr);

#define DECODE_ADD_FUNCTION(reg) \
	m_decoderMap.emplace(reg, std::bind(&FavoriteAttributesPrivate::r##reg, d, std::placeholders::_1));

#define DECODE_ADD_MUTI_FUNCTION(reg) \
	m_multiDecoderMap.emplace(reg, std::bind(&FavoriteAttributesPrivate::r##reg, d, std::placeholders::_1));
class FavoriteAttributesPrivate;
class EquipmentAction;

class FavoriteAttributes : public QObject
{
	using this_type = FavoriteAttributes;
	using decoder_func = std::function<void(quint16)>;
	using multi_decoder_func = std::function<void(QList<quint16>)>;
	Q_OBJECT
	Q_PROPERTY(double enc1 READ enc1 NOTIFY enc1Changed)
	Q_PROPERTY(double enc2 READ enc2 NOTIFY enc2Changed)
	Q_PROPERTY(double enc3 READ enc3 NOTIFY enc3Changed)
	Q_PROPERTY(double enc1L1 READ enc1L1 NOTIFY enc1L1Changed)
	Q_PROPERTY(double enc1L7 READ enc1L7 NOTIFY enc1L7Changed)
	Q_PROPERTY(double headMin READ headMin NOTIFY headMinChanged)
	Q_PROPERTY(double headMax READ headMax NOTIFY headMaxChanged)
	Q_PROPERTY(double head READ head NOTIFY headChanged)
	Q_PROPERTY(bool backHasDrill READ backHasDrill NOTIFY backHasDrillChanged)
	Q_PROPERTY(bool middeHasDrill READ middeHasDrill NOTIFY middeHasDrillChanged)
	Q_PROPERTY(bool frontHasDrill READ frontHasDrill NOTIFY frontHasDrillChanged)
	Q_PROPERTY(bool autoPush READ autoPush NOTIFY autoPushChanged)
	Q_PROPERTY(bool autoPull READ autoPull NOTIFY autoPullChanged)
	Q_PROPERTY(bool isStarted READ isStarted NOTIFY isStartedChanged)
	Q_PROPERTY(bool isStopped READ isStopped NOTIFY isStoppedChanged)
	Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged)
	Q_PROPERTY(bool okState READ okState NOTIFY okStateChanged)
	Q_PROPERTY(bool cancelState READ cancelState NOTIFY cancelStateChanged)
	Q_PROPERTY(bool pumpRunning READ pumpRunning NOTIFY pumpRunningChanged)
	Q_PROPERTY(int do1 READ do1 NOTIFY do1Changed)																					//DO1
	Q_PROPERTY(int do2 READ do2 NOTIFY do2Changed)																					//DO2
	Q_PROPERTY(int do3 READ do3 NOTIFY do3Changed)																					//DO3
	Q_PROPERTY(int do4 READ do4 NOTIFY do4Changed)																					//DO4
	Q_PROPERTY(int do5 READ do5 NOTIFY do5Changed)																					//DO5
	Q_PROPERTY(int do6 READ do6 NOTIFY do6Changed)																					//DO6
	Q_PROPERTY(int do7 READ do7 NOTIFY do7Changed)																					//DO7
	Q_PROPERTY(int do8 READ do8 NOTIFY do8Changed)																					//DO8
	Q_PROPERTY(int do9 READ do9 NOTIFY do9Changed)																					//DO9
	Q_PROPERTY(int do10 READ do10 NOTIFY do10Changed)																				//DO10
	Q_PROPERTY(int do11 READ do11 NOTIFY do11Changed)																				//DO11
	Q_PROPERTY(int do12 READ do12 NOTIFY do12Changed)																				//DO12
	Q_PROPERTY(int do13 READ do13 NOTIFY do13Changed)																				//DO13
	Q_PROPERTY(int do14 READ do14 NOTIFY do14Changed)																				//DO14
	Q_PROPERTY(int do15 READ do15 NOTIFY do15Changed)																				//DO15
	Q_PROPERTY(int do16 READ do16 NOTIFY do16Changed)																				//DO16
	Q_PROPERTY(int do17 READ do17 NOTIFY do17Changed)																				//DO17
	Q_PROPERTY(int do18 READ do18 NOTIFY do18Changed)																				//DO18
	Q_PROPERTY(int do19 READ do19 NOTIFY do19Changed)																				//DO19
	Q_PROPERTY(int do20 READ do20 NOTIFY do20Changed)																				//DO20
	Q_PROPERTY(int do21 READ do21 NOTIFY do21Changed)																				//DO21
	Q_PROPERTY(int do22 READ do22 NOTIFY do22Changed)																				//DO22
	Q_PROPERTY(int do23 READ do23 NOTIFY do23Changed)																				//DO23
	Q_PROPERTY(int do24 READ do24 NOTIFY do24Changed)																				//DO24
	Q_PROPERTY(int do25 READ do25 NOTIFY do25Changed)																				//DO25
	Q_PROPERTY(int do26 READ do26 NOTIFY do26Changed)																				//DO26
	Q_PROPERTY(int do27 READ do27 NOTIFY do27Changed)																				//DO27
	Q_PROPERTY(int do28 READ do28 NOTIFY do28Changed)																				//DO28
	Q_PROPERTY(int do29 READ do29 NOTIFY do29Changed)																				//DO29
	Q_PROPERTY(int do30 READ do30 NOTIFY do30Changed)																				//DO30
	Q_PROPERTY(int do31 READ do31 NOTIFY do31Changed)																				//DO31
	Q_PROPERTY(int do32 READ do32 NOTIFY do32Changed)																				//DO32
	Q_PROPERTY(int do33 READ do33 NOTIFY do33Changed)																				//DO33
	Q_PROPERTY(int do34 READ do34 NOTIFY do34Changed)																				//DO34
	Q_PROPERTY(int do35 READ do35 NOTIFY do35Changed)																				//DO35
	Q_PROPERTY(int do36 READ do36 NOTIFY do36Changed)																				//DO36
	Q_PROPERTY(int do37 READ do37 NOTIFY do37Changed)																				//DO37
	Q_PROPERTY(int do38 READ do38 NOTIFY do38Changed)																				//DO38
	Q_PROPERTY(int do39 READ do39 NOTIFY do39Changed)																				//DO39
	Q_PROPERTY(int do40 READ do40 NOTIFY do40Changed)																				//DO40
	Q_PROPERTY(int do41 READ do41 NOTIFY do41Changed)																				//DO41
	Q_PROPERTY(int do42 READ do42 NOTIFY do42Changed)																				//DO42
	Q_PROPERTY(int do43 READ do43 NOTIFY do43Changed)																				//DO43
	Q_PROPERTY(int do44 READ do44 NOTIFY do44Changed)																				//DO44
	Q_PROPERTY(int do45 READ do45 NOTIFY do45Changed)																				//DO45
	Q_PROPERTY(int do46 READ do46 NOTIFY do46Changed)																				//DO46
	Q_PROPERTY(int do47 READ do47 NOTIFY do47Changed)																				//DO47
	Q_PROPERTY(int do48 READ do48 NOTIFY do48Changed)																				//DO48
	Q_PROPERTY(int do49 READ do49 NOTIFY do49Changed)																				//DO49
	Q_PROPERTY(int do50 READ do50 NOTIFY do50Changed)																				//DO50
	Q_PROPERTY(int do51 READ do51 NOTIFY do51Changed)																				//DO51
	Q_PROPERTY(int do52 READ do52 NOTIFY do52Changed)																				//DO52
	Q_PROPERTY(int do53 READ do53 NOTIFY do53Changed)																				//DO53
	Q_PROPERTY(int do54 READ do54 NOTIFY do54Changed)																				//DO54
	Q_PROPERTY(int do55 READ do55 NOTIFY do55Changed)																				//DO55
	Q_PROPERTY(int do56 READ do56 NOTIFY do56Changed)																				//DO56
	Q_PROPERTY(int do57 READ do57 NOTIFY do57Changed)																				//DO57
	Q_PROPERTY(int do58 READ do58 NOTIFY do58Changed)																				//DO58
	Q_PROPERTY(int do59 READ do59 NOTIFY do59Changed)																				//DO59
	Q_PROPERTY(int do60 READ do60 NOTIFY do60Changed)																				//DO60
	Q_PROPERTY(int do61 READ do61 NOTIFY do61Changed)																				//DO61
	Q_PROPERTY(int do62 READ do62 NOTIFY do62Changed)																				//DO62
	Q_PROPERTY(int do63 READ do63 NOTIFY do63Changed)																				//DO63
	Q_PROPERTY(int do64 READ do64 NOTIFY do64Changed)																				//DO64
	Q_PROPERTY(int ai1 READ ai1 NOTIFY ai1Changed)																					//ai1
	Q_PROPERTY(int ai2 READ ai2 NOTIFY ai2Changed)																					//ai2
	Q_PROPERTY(int ai3 READ ai3 NOTIFY ai3Changed)																					//ai3
	Q_PROPERTY(int ai4 READ ai4 NOTIFY ai4Changed)																					//ai4
	Q_PROPERTY(int ai5 READ ai5 NOTIFY ai5Changed)																					//ai5
	Q_PROPERTY(int ai6 READ ai6 NOTIFY ai6Changed)																					//ai6
	Q_PROPERTY(int ai7 READ ai7 NOTIFY ai7Changed)																					//ai7
	Q_PROPERTY(int ai8 READ ai8 NOTIFY ai8Changed)																					//ai8
	Q_PROPERTY(int ai9 READ ai9 NOTIFY ai9Changed)																					//ai9
	Q_PROPERTY(int ai10 READ ai10 NOTIFY ai10Changed)																				//ai10
	Q_PROPERTY(int ai11 READ ai11 NOTIFY ai11Changed)																				//ai11
	Q_PROPERTY(int ai12 READ ai12 NOTIFY ai12Changed)																				//ai12
	Q_PROPERTY(int ai13 READ ai13 NOTIFY ai13Changed)																				//ai13
	Q_PROPERTY(int ai14 READ ai14 NOTIFY ai14Changed)																				//ai14
	Q_PROPERTY(int ai15 READ ai15 NOTIFY ai15Changed)																				//ai15
	Q_PROPERTY(int ai16 READ ai16 NOTIFY ai16Changed)																				//ai16
	Q_PROPERTY(int di READ di NOTIFY diChanged)																						//di

public:
	double enc1() const;
	double enc2() const;
	double enc3() const;
	double enc1L1() const;
	double enc1L7() const;
	double headMin() const;
	double headMax() const;
	double head() const;
	bool backHasDrill() const;
	bool middeHasDrill() const;
	bool frontHasDrill() const;
	bool autoPush() const;
	bool autoPull() const;
	bool isStarted() const;
	bool isStopped() const;
	bool isPaused() const;
	bool okState() const;
	bool cancelState() const;
	bool pumpRunning() const;
	int do1() const;
	int do2() const;
	int do3() const;
	int do4() const;
	int do5() const;
	int do6() const;
	int do7() const;
	int do8() const;
	int do9() const;
	int do10() const;
	int do11() const;
	int do12() const;
	int do13() const;
	int do14() const;
	int do15() const;
	int do16() const;
	int do17() const;
	int do18() const;
	int do19() const;
	int do20() const;
	int do21() const;
	int do22() const;
	int do23() const;
	int do24() const;
	int do25() const;
	int do26() const;
	int do27() const;
	int do28() const;
	int do29() const;
	int do30() const;
	int do31() const;
	int do32() const;
	int do33() const;
	int do34() const;
	int do35() const;
	int do36() const;
	int do37() const;
	int do38() const;
	int do39() const;
	int do40() const;
	int do41() const;
	int do42() const;
	int do43() const;
	int do44() const;
	int do45() const;
	int do46() const;
	int do47() const;
	int do48() const;
	int do49() const;
	int do50() const;
	int do51() const;
	int do52() const;
	int do53() const;
	int do54() const;
	int do55() const;
	int do56() const;
	int do57() const;
	int do58() const;
	int do59() const;
	int do60() const;
	int do61() const;
	int do62() const;
	int do63() const;
	int do64() const;
	int ai1() const;
	int ai2() const;
	int ai3() const;
	int ai4() const;
	int ai5() const;
	int ai6() const;
	int ai7() const;
	int ai8() const;
	int ai9() const;
	int ai10() const;
	int ai11() const;
	int ai12() const;
	int ai13() const;
	int ai14() const;
	int ai15() const;
	int ai16() const;
	int di() const;

public:
	FavoriteAttributes(QObject* parent = nullptr);
	~FavoriteAttributes();
	bool hasFavorite(int address) const;
	bool hasMulti(int address, int& byteCount) const;
	bool update(int address, quint16 value);
	bool update(int address, QList<quint16> values);
signals:
	void enc1L1Changed();
	void enc1L7Changed();
	void enc1Changed();
	void enc2Changed();
	void enc3Changed();
	void headMinChanged();
	void headMaxChanged();
	void headChanged();
	void backHasDrillChanged();
	void middeHasDrillChanged();
	void frontHasDrillChanged();
	void pumpRunningChanged();
	void autoPushChanged();
	void autoPullChanged();
	void isStartedChanged();
	void isStoppedChanged();
	void isPausedChanged();
	void okStateChanged();
	void cancelStateChanged();
	void do1Changed();
	void do2Changed();
	void do3Changed();
	void do4Changed();
	void do5Changed();
	void do6Changed();
	void do7Changed();
	void do8Changed();
	void do9Changed();
	void do10Changed();
	void do11Changed();
	void do12Changed();
	void do13Changed();
	void do14Changed();
	void do15Changed();
	void do16Changed();
	void do17Changed();
	void do18Changed();
	void do19Changed();
	void do20Changed();
	void do21Changed();
	void do22Changed();
	void do23Changed();
	void do24Changed();
	void do25Changed();
	void do26Changed();
	void do27Changed();
	void do28Changed();
	void do29Changed();
	void do30Changed();
	void do31Changed();
	void do32Changed();
	void do33Changed();
	void do34Changed();
	void do35Changed();
	void do36Changed();
	void do37Changed();
	void do38Changed();
	void do39Changed();
	void do40Changed();
	void do41Changed();
	void do42Changed();
	void do43Changed();
	void do44Changed();
	void do45Changed();
	void do46Changed();
	void do47Changed();
	void do48Changed();
	void do49Changed();
	void do50Changed();
	void do51Changed();
	void do52Changed();
	void do53Changed();
	void do54Changed();
	void do55Changed();
	void do56Changed();
	void do57Changed();
	void do58Changed();
	void do59Changed();
	void do60Changed();
	void do61Changed();
	void do62Changed();
	void do63Changed();
	void do64Changed();
	void ai1Changed();
	void ai2Changed();
	void ai3Changed();
	void ai4Changed();
	void ai5Changed();
	void ai6Changed();
	void ai7Changed();
	void ai8Changed();
	void ai9Changed();
	void ai10Changed();
	void ai11Changed();
	void ai12Changed();
	void ai13Changed();
	void ai14Changed();
	void ai15Changed();
	void ai16Changed();
	void diChanged();
	void message(QJsonObject const&);
private:
	std::unique_ptr<FavoriteAttributesPrivate> m_parser;
	std::multimap<int, decoder_func> m_decoderMap;
	std::multimap<int, multi_decoder_func> m_multiDecoderMap;
	Q_DECLARE_PRIVATE_D(m_parser, FavoriteAttributes)

};



